package flex.cc.nursing.controller;

import java.io.File;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import flex.cc.PublicUtil;
import flex.cc.core.support.BaseController;
import flex.cc.nursing.dto.entity.AccountDataEntity;
import flex.cc.nursing.service.AccountDataService;
import flex.cc.store.service.PackageExportService;
import flex.cc.util.FileDownloadUtil;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * 
 * @author WANGCONG
 * 2022年3月22日下午14:26:37
 * @desc 预发核算数据管理
 */
@RestController
@RequestMapping(value = "/nursing/accountData")
public class AccountDataController extends BaseController{

	@Resource
    private AccountDataService accountDataService;
	@Resource
    private PackageExportService packageExportService;
	
	/**
	 *
	 * @author WANGCONG
	 * 2022年3月22日下午14:31:41
	 * @desc 核算数据导出：根据发送时间、渠道方组合参数
	 */
	@PostMapping(value = "/export")
    @ApiOperation(httpMethod = "POST", value = "核算数据导出")
	public void export(HttpServletRequest request, HttpServletResponse response, 
			@ApiParam(name = "storeCoupon", value = "卡券信息") @RequestBody Map<String, Object> reqVo){
        logger.info("核算数据导出");
        AccountDataEntity accountData = new AccountDataEntity();
        accountData.setSource( PublicUtil.isNotEmpty(reqVo.get("channel")) ? "ZXHY" : null );
        accountData.setStartTime( PublicUtil.isNotEmpty(reqVo.get("startTime")) ? reqVo.get("startTime").toString() : null );
        accountData.setEndTime( PublicUtil.isNotEmpty(reqVo.get("endTime")) ? reqVo.get("endTime").toString() : null );
        String fileParentPath = System.getProperty("user.dir") + File.separator + "package" + File.separator + System.currentTimeMillis();
        String fileName = "预发核算数据列表";
        packageExportService.downLoadAccountData(request, response, accountData, fileParentPath, fileName);
        String filepath = fileParentPath + File.separator + fileName + ".xlsx";
        FileDownloadUtil.downloadByFilepath(request, response, filepath);
    }
	
	
}
